package 笔试题.博乐科技;

public class 最大价值礼物 {
    public int maximumValue(int[] arr) {
        //动态规划
        if (arr == null || arr.length == 0) return -1;
        if (arr.length == 1) return arr[0];
        int[] dp = new int[arr.length + 1];
        dp[0] = 0;
        dp[1] = arr[0];
        for (int i = 2; i <= arr.length; i++) {
            dp[i] = Math.max(dp[i - 1], dp[i - 2] + arr[i - 1]);
        }
        return dp[arr.length];
    }
}
